//
// Created by xili on 2024/8/21 16:18.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    vector<int> findThePrefixCommonArray(vector<int> &A, vector<int> &B) {
        unordered_set<int> usA;
        unordered_set<int> usB;
        vector<int> ans;
        int n = A.size();
        int cnts;
        for (int i = 0; i < n; i++) {
            usA.insert(A[i]);
            usB.insert(B[i]);
            cnts += usA.count(B[i]) ? 1 : 0;
            cnts += usB.count(A[i]) ? 1 : 0;
            cnts += A[i] == B[i] ? -1 : 0;
            ans.push_back(cnts);
        }
        return ans;
    }
};